package cn.zwx.distributed.svc;

import cn.zwx.base.entity.ResponseEntity;
import cn.zwx.base.exception.BizWrapException;
import cn.zwx.distributed.svc.fallback.DistributedApiFallback;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.validation.constraints.NotBlank;

/**
 * @author zhangwenxue
 */
@FeignClient(name = "distributed-svc",path = "/distributed")
public interface DistributedServiceApi extends FallbackFactory<DistributedApiFallback> {

    @PostMapping
    DistributedApiFallback create(Throwable cause);

    /**
     * 获取全局分布式ID
     * @return UID
     * @throws BizWrapException BizWrapException
     */
    @RequestMapping(value = "/get",method = RequestMethod.POST)
    ResponseEntity<String> getDistributedId() throws BizWrapException;

    /**
     * 解析全局分布式ID
     * @param distributedId 全局id
     * @return Parsed info
     * @throws BizWrapException 业务异常
     */
    @RequestMapping(value = "/parse",method = RequestMethod.POST)
    ResponseEntity<String> parsDistributedId(@RequestParam(value = "全局id") @NotBlank(message = "全局id不能为空")
                                              String distributedId) throws BizWrapException;

}
